import { ctx2 } from '@app-base/module';
import React from 'react';
import DocModal from './DocModal';

interface InsertDocModalProps {
  open: boolean;
  onClose: VoidFunction;
}

export const InsertDocModal: React.FC<InsertDocModalProps> = ({
  open,
  onClose,
}) => {
  const handleOk = async (selectedRows: CadDocument.FullDocumentInfo[]) => {
    await Promise.all(
      selectedRows.map((doc) =>
        ctx2.commandCenters.assemblyCommands.addSubDoc(
          doc.documentUuid,
          doc.latestVersion.version.toString(),
        ),
      ),
    );
  };

  return (
    <DocModal
      open={open}
      title='插入文档'
      okText='插入'
      rowSelectionType='checkbox'
      onOk={handleOk}
      onClose={onClose}
    />
  );
};
